/**
 * 
 */
package edu.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import edu.dao.BaseDao;
import edu.entity.Module;
import edu.entity.User;
import edu.entity.UserRole;

/**
 * @author yanshichuan
 * 2013年9月1日 下午9:39:30
 */
@Service("userRoleService")
public class UserRoleService extends BaseService {
	@Autowired
	private BaseDao baseDao;
	public void insertUserRole(UserRole userRole) throws Exception {
		if(userRole!=null){
			baseDao.insert(userRole);
		}
	}
	
	public void updateUserRole(UserRole userRole) throws Exception {
		if(userRole!=null){
			baseDao.update(userRole);
		}
	}
	
	public void deleteUserRole(UserRole userRole) throws Exception {
		if(userRole!=null){
			baseDao.delete(userRole);
		}
	}
	
	public void deleteUserRoleByUserId(String userId) throws Exception {
		if(userId!=null){
			baseDao.batchDeleteByHql("delete from UserRole ur where ur.user.id='"+userId+"'");
		}
	}
	
	public void deleteUserRoleByRoleId(String roleId) throws Exception {
		if(roleId!=null){
			baseDao.batchDeleteByHql("delete from UserRole ur where ur.role.id='"+roleId+"'");
		}
	}
	
	public UserRole selectUserRoleById(String id) throws Exception {
		UserRole userRole=null;
		if(id!=null){
			userRole=(UserRole) baseDao.selectObjById(UserRole.class, id);
		}
		return userRole;
	}
	
	public List<UserRole> selectUserRolesByUserId(String userId) throws Exception{
		List<UserRole> list=null;
		if(userId!=null){
			list=baseDao.selectPojoByHql("from UserRole ur where ur.user.id='"+userId+"'");
		}
		return list;
	}
	
	public List<UserRole> selectUserRolesByRoleId(String roleId) throws Exception{
		List<UserRole> list=null;
		if(roleId!=null){
			list=baseDao.selectPojoByHql("from UserRole ur where ur.role.id='"+roleId+"'");
		}
		return list;
	}
	
	 public void deleteUserRoleById(String id) throws Exception {
		 if(id!=null){
	    	this.baseDao.deleteById(UserRole.class, id);
		 }
	  }
	    
}
